package com.yanqu.road.server.cmd.manor;

import com.yanqu.road.pb.manor.ManorProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.manor.ManorModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/5/19 14:25
 */
@Cmd(code = GameProtocol.S_MANOR_OBJECT_CHANGE_NAME, desc = "庄园物件改名")
public class ManorObjectChangeNameCmd extends AbstractCommand {
    private int id;
    private String nickName;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ManorProto.ManorObjectChangeNameReqMsg msg = ManorProto.ManorObjectChangeNameReqMsg.parseFrom(packet.getBytes());
        id = msg.getId();
        nickName = msg.getNickName();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(ManorModule.class).changeNickName(id ,nickName);
    }

    @Override
    public void sendData(GamePlayer player) {
        ManorProto.ManorObjectChangeNameRespMsg.Builder respMsg = ManorProto.ManorObjectChangeNameRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(ClientProtocol.U_MANOR_OBJECT_CHANGE_NAME, respMsg);
    }
}
